﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Power_Default : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string strPage = Request["page"];
            int page = 1;
            try
            {
                page = int.Parse(strPage);
                if (page < 1)
                {
                    page = 1;
                }
            }
            catch (Exception ex)
            {
                page = 1;
            }
            bd(page);
        }
    }
    public int GetPage()
    {
        return AspNetPager1.CurrentPageIndex;
    }
    void bd(int page)
    {
        CMSModel.CMSEntities dal = DAL.DBManager.GetCmsEmtity();
        var powers = dal.Power.AsQueryable();
        var id = Server.UrlDecode(Request["id"]);
        string powerid="0";
        if (id != null)
            powerid =id;
        var name = Server.UrlDecode(Request["name"]);
        if (id!=null)
            powers = powers.Where(x => x.Id == powerid);
        if (!string.IsNullOrEmpty(name))
            powers = powers.Where(x => x.Name.Contains(name));
        AspNetPager1.RecordCount = powers.Count();
        AspNetPager1.CurrentPageIndex = page;
        powers = powers.OrderBy(x => "id").Skip((page - 1) * AspNetPager1.PageSize).Take(AspNetPager1.PageSize);
        Repeater1.DataSource = powers;
        Repeater1.DataBind();
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem
         || e.Item.ItemType == ListItemType.Item)
        {
            string isenable = (e.Item.FindControl("lblIsEnable") as Label).Text;
            string pid = (e.Item.FindControl("lblPid") as Label).Text;
            if (pid == "0")
                (e.Item.FindControl("lblPid") as Label).Text = "一级菜单";
            if (isenable == "True")
                (e.Item.FindControl("lblIsEnable") as Label).Text = "正常";
            else
                (e.Item.FindControl("lblIsEnable") as Label).Text = "禁用";
        }
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        bd(AspNetPager1.CurrentPageIndex);
    }
    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        bd(AspNetPager1.CurrentPageIndex);
    }
}